<?php
function make_bnsbalance($mv_type,$mv_amount,$mv_client) {
	// Get Last
	$pv_balance = $GLOBALS['MYT']->db_array("SELECT bac_ID, bac_balance FROM bonusaccounts WHERE bac_Client = {$mv_client}");
	if (!isset($pv_balance[1])) {
		$CardAc = $GLOBALS['MYT']->db_array("SELECT car_ID FROM bonuscards WHERE car_Client = {$mv_client} AND car_Status NOT IN (1,5)");
	$GLOBALS['MYT']->db_query("INSERT INTO bonusaccounts (bac_Client, bac_Card, bac_balance) VALUES ({$mv_client},{$CardAc[1]['car_ID']},0)");
	}
	if ($mv_type == 1) {
		$tmpBalance = number_format($pv_balance[1]['bac_balance'],2,'.','')+number_format($mv_amount,2,'.','');
	} elseif($mv_type == 0) {
		$tmpBalance = number_format($pv_balance[1]['bac_balance'],2,'.','')-number_format($mv_amount,2,'.','');
	}
	$GLOBALS['MYT']->db_query("UPDATE bonusaccounts SET bac_balance = {$tmpBalance} WHERE bac_ID = {$pv_balance[1]['bac_ID']}");
	return $tmpBalance;
}